<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >

<xsl:output method="html" indent="yes"/>

<xsl:include href="http://localhost:8080/wsd_assign2/header.xsl" />
<xsl:param name="page" select="1" />
<xsl:param name="pageSize" select="1" />
<xsl:param name="total" select="./result/total" />
<xsl:param name="pageCount" select="ceiling($total div $pageSize)" />
<xsl:param name="counter" select = "0" />
<xsl:param name="title"  />
<xsl:template name="loop">
  <xsl:param name="var"></xsl:param>
  <xsl:choose>
    <xsl:when test="$var &lt;= $pageCount">
    <xsl:if test="$var = $page">
     <li class="currentPage"> <xsl:value-of select="$var"></xsl:value-of></li>
     </xsl:if>
     <xsl:if test="$var != $page">
     <li class="otherPage"> <a href="main.jsp?url=collection&amp;xsl=collection&amp;order=name&amp;page={$var}"><xsl:value-of select="$var"></xsl:value-of></a></li>
     </xsl:if>
      <xsl:call-template name="loop">
        <xsl:with-param name="var">
        <xsl:number value="number($var)+1" />
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


  
  


<xsl:template match="collections">

 <link type="text/css" rel="stylesheet" href="css/collection.css" />
 
 
 
 
 
      
      
   <!-- main content for displaying category -->      
      
  
    <table id="tableArea">
		<thead><th>Thumbnail</th><th>collection</th><th>Num_Item</th></thead>
		<tbody>
		 <xsl:apply-templates/>
		 </tbody>
	</table>
	
	<!-- Prev link for pagination -->
 	<ul class="pageNoList">
      <xsl:choose>
       <xsl:when test="number($page) &gt; 1">
        
         <li class="otherPage"><a><xsl:attribute name="href">main.jsp?url=collection&amp;xsl=collection&amp;order=name&amp;page=<xsl:value-of select="number($page)-1"/></xsl:attribute> &lt;&lt;Prev</a>
       </li>
       </xsl:when>
       <xsl:otherwise>
        <li> <span class="inactiveButton">&lt;&lt;Prev</span></li>
       </xsl:otherwise>
      </xsl:choose>
      
<!-- Page Number bar -->
	
	 <xsl:call-template name="loop">
	    <xsl:with-param name="var">1</xsl:with-param>
	  </xsl:call-template>
  	
  	
 <!-- Next link for pagination -->  	
      
       <xsl:choose>
       <xsl:when test="number($page) &lt; $pageCount">
        <li class="otherPage"><a>
         <xsl:attribute name="href">main.jsp?url=collection&amp;xsl=collection&amp;order=name&amp;page=<xsl:value-of select="number($page)+1"/></xsl:attribute>
          Next&gt;&gt;
        </a></li>
       </xsl:when>
       <xsl:otherwise>
        <li>
          <span class="inactiveButton">Next&gt;&gt;</span>
        </li>
       </xsl:otherwise>
      </xsl:choose>
      
      </ul>
   
</xsl:template>

<xsl:template match="collection">
	<!-- <xsl:variable name="itemsURI"><xsl:value-of select="items_uri" /></xsl:variable>  -->
	
	<xsl:variable name="imgUrl"><xsl:value-of select="thumbnail/url" /></xsl:variable>

	<xsl:variable name="itemsId"><xsl:value-of select="id" /></xsl:variable>

		<tr>
		<td><xsl:if test="$imgUrl != ''">
	    	<img src="{$imgUrl}" width="100" height="100"></img>
	        </xsl:if>
	  	    <xsl:if test="$imgUrl=''" ><img src="img/cry-face-main.jpg" width="100" height="100"></img></xsl:if></td>
	  	<td><a href="main.jsp?url=collection/{$itemsId}/items&amp;xsl=collectionItems&amp;order=title"><xsl:value-of select="name"/></a></td>
	    <td class="rightTD"><xsl:value-of select="num_items"/></td></tr>
	
</xsl:template>


<xsl:template match="status"></xsl:template>
<xsl:template match="end"></xsl:template>
<xsl:template match="start"></xsl:template>
<xsl:template match="result/result"></xsl:template>
<xsl:template match="total"></xsl:template>


</xsl:stylesheet>
